import * as Helper from "./common/helper";
import CDN from './common/cdn_files';
import * as Status from "./status";

import "./styles/main.scss";

const defaultStatus: Status.MainStatus = {
    page: "home"
}

async function Render(status: Status.MainStatus) {
    const React = await import("react");
    const ReactDom = await import("react-dom");

    async function GetPage(page: Status.Page) {
        switch (page) {
            case "home":
                const Home = (await import("./pages/home")).Home;
                return <Home onFunctionSelected={async func => await Render({ page: func })} />
            case "localGame":
                const LocalGame = (await import("./pages/localGame")).LocalGame;
                return <LocalGame />;
        }
    }
    const Page = await (GetPage(status.page));

    ReactDom.render(
        Page,
        document.body);
}

Promise
    .all([
        Helper.EnsureDocumentLoaded(),
        Helper.EnsureJS(CDN.react),
        Helper.EnsureJS(CDN.react_dom)
    ])
    .then(async () => await Render(defaultStatus));